<template>
    <div class="EditPostionPopup">
        <popup ref="popupRef" :title="popupTitle" :async="true" width="550px" @confirm="handleSubmit" @close="handleClose">
            <el-form ref="formRef" :model="formData" label-width="84px" :rules="formRules">
				<el-form-item label="职务名称" prop="Name">
				    <el-input v-model="formData.Name" placeholder="请输入职务名称" clearable />
				</el-form-item>
				<el-form-item label="批准任职时间" prop="AppointmentDate">
                    <el-date-picker v-model="formData.AppointmentDate" type="date" />
                </el-form-item>
				<el-form-item label="连续任职时间" prop="ReappointmentDate">
                    <el-date-picker v-model="formData.ReappointmentDate" type="date" />
                </el-form-item>
				<el-form-item label="任职机构代码" prop="OrganizationCode">
                    <el-input v-model="formData.OrganizationCode" placeholder="请输入任职机构代码" clearable />
                </el-form-item>
				<el-form-item label="批准机构代码" prop="PassOrganizationCode">
                    <el-input v-model="formData.PassOrganizationCode" placeholder="请输入批准机构代码" clearable />
                </el-form-item>
				<el-form-item label="职务层次" prop="GradeName">
                    <el-input v-model="formData.GradeName" placeholder="请输入职务层次" clearable />
                </el-form-item>
				<el-form-item label="职务类别" prop="Category">
                    <el-input v-model="formData.Category" clearable />
                </el-form-item> 
				<el-form-item label="多职务主次序号" prop="No">
                    <el-input v-model="formData.No" clearable />
                </el-form-item> 
				<el-form-item label="从事工作" prop="Job">
                    <el-input v-model="formData.Job" clearable />
                </el-form-item> 
				<el-form-item label="任职状态" prop="AppointmentStatus">
                    <el-input v-model="formData.AppointmentStatus" clearable />
                </el-form-item> 
				<el-form-item label="批准文号" prop="OrderNnumber">
                    <el-input v-model="formData.OrderNnumber" clearable />
                </el-form-item> 
				<el-form-item label="工作岗位" prop="TypeOfWork">
                    <el-input v-model="formData.TypeOfWork" clearable />
                </el-form-item> 
				<el-form-item label="任职变动类别" prop="AppointmentOrganizationCategory">
                    <el-input v-model="formData.AppointmentOrganizationCategory" clearable />
                </el-form-item> 
				<el-form-item label="任职机构名称" prop="OrganizationName">
                    <el-input v-model="formData.OrganizationName" clearable />
                </el-form-item> 
				<el-form-item label="批准免职机关" prop="	PassOrganizationName">
                    <el-input v-model="formData.PassOrganizationName" clearable />
                </el-form-item> 
				<el-form-item label="批准免职日期" prop="RfoDate">
                    <el-date-picker v-model="formData.RfoDate" type="date" />
                </el-form-item>
				<el-form-item label="免职原因" prop="RfoRemark">
                    <el-input v-model="formData.RfoRemark" clearable />
                </el-form-item>
				<el-form-item label="免职文号" prop="RfoOrderNumber">
                    <el-input v-model="formData.RfoOrderNumber" clearable />
                </el-form-item>
				<el-form-item label="班子成员类别" prop="TeamCategory">
                    <el-input v-model="formData.TeamCategory" clearable />
                </el-form-item>
<!-- 
                
                

                
                <el-form-item label="履历类别" prop="Category">
                    <el-select class="w-[280px]" v-model="formData.Category">
                        <el-option v-for="(item, key) in optionData.Category" :key="key" :label="item.name"
                            :value="item.value" />
                    </el-select>
                </el-form-item>

                
                <el-form-item label="截至时间" prop="EndDate">
                    <el-date-picker v-model="formData.EndDate" type="date" />
                </el-form-item>
                -->
            </el-form>
        </popup>
    </div>
</template>
<script lang="ts" setup name="EditPostionPopup">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'

import { EditPostions } from '@/api/consumer'

const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
const popupTitle = computed(() => {
    return mode.value == 'edit' ? '编辑职务信息' : '添加职务信息'
})
const props = defineProps(['member_id']) /**从view.vue传递参数 */
const formData = reactive({
    id: 0,
    member_id: props.member_id,
    Name: '',
    AppointmentDate: '',
    ReappointmentDate: '',
    OrganizationCode: '',
    PassOrganizationCode: '',
    GradeName: '',
	No: '',
	Job: '',
	AppointmentStatus: '',
	OrderNnumber: '',
	TypeOfWork: '',
	AppointmentOrganizationCategory: '',
	OrganizationName: '',
	PassOrganizationName: '',
	RfoDate: '',
	RfoRemark: '',
	RfoOrderNumber: '',
	TeamCategory: '',
    Category: ''
})

const formRules = reactive({
     Name: [
         {
             required: true,
             message: '请输入职务名称',
             trigger: ['blur']
         }
     ],
     AppointmentDate: [
         {
             required: true,
             message: '请输入批准任职时间',
             trigger: ['blur']
         }
     ],
     OrganizationCode: [
         {
             required: true,
             message: '请输入任职机构代码',
             trigger: ['blur']
         }
     ]
})


const handleSubmit = async () => {
    await formRef.value?.validate()
    console.log('学历表单内容', formData)
    await EditPostions(formData)
    //mode.value == 'edit' ? await adminEdit(formData) : await adminAdd(formData)
    popupRef.value?.close()
    emit('success')
}

const open = (type = 'add') => {
    mode.value = type
    popupRef.value?.open()
}

const setFormData = async (row: any) => {
    formData.id = row.id
    const data = await EditPostions({
        id: row.id,
    		 mode:'get'
    })
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            formData[key] = data[key]
        }
    }
}

const handleClose = () => {
    emit('close')
}

defineExpose({
    open,
    setFormData
})
</script>
